
//#include "stdafx.h"

#ifdef __LINUX
#else
#include <exception>
#ifdef __LINUX
#else
#include <eh.h>
#include <windows.h>
#endif
#define CAST_STR(a) case a:return #a;

namespace KCore
{

class structured_exception : public std::exception
{

public:
	structured_exception(unsigned code,EXCEPTION_POINTERS * info) throw(){
		m_code = code;
		m_info = info;
	}
	const char *what() const
	{
		switch(m_code)
		{
			CAST_STR(EXCEPTION_ACCESS_VIOLATION        );
			CAST_STR(EXCEPTION_DATATYPE_MISALIGNMENT   );
			CAST_STR(EXCEPTION_BREAKPOINT              );
			CAST_STR(EXCEPTION_SINGLE_STEP             );
			CAST_STR(EXCEPTION_ARRAY_BOUNDS_EXCEEDED   );
			CAST_STR(EXCEPTION_FLT_DENORMAL_OPERAND    );
			CAST_STR(EXCEPTION_FLT_DIVIDE_BY_ZERO      );
			CAST_STR(EXCEPTION_FLT_INEXACT_RESULT      );
			CAST_STR(EXCEPTION_FLT_INVALID_OPERATION   );
			CAST_STR(EXCEPTION_FLT_OVERFLOW            );
			CAST_STR(EXCEPTION_FLT_STACK_CHECK         );
			CAST_STR(EXCEPTION_FLT_UNDERFLOW           );
			CAST_STR(EXCEPTION_INT_DIVIDE_BY_ZERO      );
			CAST_STR(EXCEPTION_INT_OVERFLOW            );
			CAST_STR(EXCEPTION_PRIV_INSTRUCTION        );
			CAST_STR(EXCEPTION_IN_PAGE_ERROR           );
			CAST_STR(EXCEPTION_ILLEGAL_INSTRUCTION     );
			CAST_STR(EXCEPTION_NONCONTINUABLE_EXCEPTION);
			CAST_STR(EXCEPTION_STACK_OVERFLOW          );
			CAST_STR(EXCEPTION_INVALID_DISPOSITION     );
			CAST_STR(EXCEPTION_GUARD_PAGE              );
			CAST_STR(EXCEPTION_INVALID_HANDLE          );
		}
		return "unknow struct exception ";
	}
private:
	unsigned m_code;
	EXCEPTION_POINTERS * m_info;
};

static void my_translator(unsigned code, EXCEPTION_POINTERS * info)
{
	throw structured_exception(code,info);
}

void utility_exception_init()
{
	_set_se_translator(my_translator);
}

};
#endif
